package com.zdj.presentation.modules.main.views;


import android.Manifest;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;

import com.zdj.aoplibrary.annotations.SecurityCheckAnnotation;
import com.zdj.aoplibrary.util.SecurityCheckManager;
import com.zdj.presentation.R;
import com.zdj.presentation.base.BaseActivity;
import com.zdj.presentation.databinding.ActivityMainBinding;
import com.zdj.presentation.modules.demo.TestGsonActivity;
import com.zdj.presentation.modules.im.views.ChatActivity;
import com.zdj.presentation.modules.login.views.LoginActivity;
import com.zdj.presentation.modules.main.handlers.MainHandler;
import com.zdj.presentation.modules.main.vms.MainVm;

/**
 * 主界面 <br/>
 * 作者 ：zdj <br/>
 * created at 16-9-25 上午8:05
 */
public class MainActivity extends BaseActivity<MainVm,ActivityMainBinding> implements MainHandler{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 初始化 权限验证模块
        SecurityCheckManager.createInstance(this);
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void initVms() {
        viewModel = new MainVm(this);
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void setViewModel2Binding() {
        viewDatabinding.setMainVm(viewModel);
        viewDatabinding.setHandlers(this);
    }

    @Override
    protected void initView() {
        viewDatabinding.linkTv.setText(Html.fromHtml(getResources().getString(R.string.url)));
        viewDatabinding.linkTv.setMovementMethod(LinkMovementMethod.getInstance());
    }

    @SecurityCheckAnnotation(declaredPermission = Manifest.permission.READ_PHONE_STATE)
    @Override
    public void gotoLogin(View view) {
        toActivity(LoginActivity.class);
    }

    @Override
    public void gotoChat(View view) {
        toActivity(ChatActivity.class);
    }

    @Override
    public void gotoTestUser(View view) {
        toActivity(TestGsonActivity.class);
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        moveTaskToBack(true);
    }
}
